package com.lagou.sqlSession;

import com.lagou.config.XMLConfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author zx
 * @date 2021/5/28 21:05
 * @description
 */
public class SqlSessionFactoryBuilder {

    /**
     * 1.dom4j解析配置文件 分装到容器
     * 2。创建sqlSessionFactory对象
     */
    public  SqlSessionFactory Build(InputStream in) throws DocumentException, PropertyVetoException {
        // 1
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);
        // 2
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;

    }
}
